{--------------------------------------}
(*
	Author : DarkCoderSc
	Web-site : Http://unremote.org/
	E-Mail : DarkCoderSc@unremote.org
			 DarkCoderSc@SynSecurity.net
	/Check if the ip/port is correct\
	\-------------------------------/
*)
{--------------------------------------}

Unit UntCheck;

interface

Uses windows,sysutils;

implementation
{MAIN---------------------------------------------------------------------------}

{Check IP/Ports utility---------------------------------------------------------}
//Check if it is a correct ip type
function checkip(ip:string) : boolean;
var x1,x2,x3,x4 : integer;
	s1,s2,s3,s4 : String;
begin
	{Parsing 4xip parts}
	s1 := Copy(ip, 1, Pos('.', ip)-1);
	Delete(ip, 1, Pos('.', ip));
	s2 := Copy(ip, 1, Pos('.', ip)-1);
	Delete(ip, 1, Pos('.', ip));
	s3 := Copy(ip, 1, Pos('.', ip)-1);
	Delete(ip, 1, Pos('.', ip));
	s4 := ip;
	{Testing if it is an integer}
	If NOT ( (TryStrToInt(s1,x1)) And (TryStrToInt(s2,x2)) And (TryStrToInt(s3,x3)) And (TryStrToInt(s4,x4)) )
	Then begin Result := False; exit; end;
	{Testing Data lenght}
	if Length(s1) > 3 then Result := false;
	if Length(s2) > 3 then Result := false;
	if Length(s3) > 3 then Result := false;
	if Length(s4) > 3 then Result := false;
	if Result = false then exit;
	{Testing Number Size}
	x1 := StrToInt(s1);
	x2 := StrToInt(s2);
	x3 := StrToInt(s3);
	x4 := StrToInt(s4);
	if x1 > 255 then Result := false;
	if x2 > 255 then Result := false;
	if x3 > 255 then Result := false;
	if x4 > 255 then Result := false;
	if Result = false then exit;
	{Now generating report}
	if Result <> False then Result := True;
end;

//Check if it is a correct port
function Checkport(port:string) : boolean;
begin
	{Checking if it is a correct integer}
	if NOT TryStrToInt(port) then Result := false;
	{Checking if it is a correct port}
	if (port > 65535) then Result := false;
	{Generating report}
	if Result <> false then Result := true; 
end;
{Check IP/Ports utility---------------------------------------------------------}